`ifndef APB_SLV_AGENT_SV
`define APB_SLV_AGENT_SV


class apb_slv_agent extends uvm_agent;

	uvm_analysis_port #(apb_transaction) 	ap;
	virtual apb_interface 								vif;
	apb_slv_driver												driver;
	apb_slv_monitor												monitor;
	apb_slv_sequencer											sequencer;
	apb_agent_configuration								cfg;

	`uvm_component_utils(apb_slv_agent)

	function new(string name = "apb_slv_agent", uvm_component parent = null);
		super.new(name, parent);
	endfunction : new

	function void build_phase(uvm_phase phase);
		super.build_phase(phase);

		ap = new("ap", this);

		if(!uvm_config_db #(apb_agent_configuration)::get(this, "", "cfg", cfg))
			`uvm_fatal("CFGGET", "cannot get config from config DB")

		if(!uvm_config_db #(virtual apb_interface)::get(this, "", "vif", vif))
			`uvm_fatal("CFGGET", "cannot get virtual interface from config DB")

		if(cfg.is_active) begin
			driver = apb_slv_driver::type_id::create("driver", this);
			sequencer = apb_slv_sequencer::type_id::create("sequencer", this);
			uvm_config_db #(virtual apb_interface)::set(this, "driver", "vif", vif);
		end

		monitor = apb_slv_monitor::type_id::create("monitor", this);
		uvm_config_db #(virtual apb_interface)::set(this, "monitor", "vif", vif);
	endfunction : build_phase

	function void connect_phase(uvm_phase phase);
		super.connect_phase(phase);
	
		if(cfg.is_active) begin
			driver.seq_item_port.connect(sequencer.seq_item_export);
		end
	endfunction : connect_phase

endclass : apb_slv_agent


`endif // APB_SLV_AGENT_SV
